package com.zoro.barn.business.service.sqldocument.business.document.controller;

import com.zoro.barn.business.service.sqldocument.conf.MongoDbConfig;
import com.zoro.barn.commons.mongodb.dao.MongoDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaoxingwu
 */
@RestController
@RequestMapping("document-delete")
public class FileDeletedController {

    private final MongoDao mongoDao;
    private final MongoDbConfig mongoDbConfig;

    public FileDeletedController(MongoDao mongoDao, MongoDbConfig mongoDbConfig) {
        this.mongoDao = mongoDao;
        this.mongoDbConfig = mongoDbConfig;
    }

    @RequestMapping("/image/{fileId}")
    public void image(@PathVariable("fileId") String fileId) {
        if (StringUtils.isBlank(fileId)) {
            return;
        }
        this.mongoDao.deleteById(mongoDbConfig.getDocumentImageDb(), fileId);
    }
}
